<?php
/**
 * Author: lf
 * Blog: https://blog.feehi.com
 * Email: job@feehi.com
 * Created at: 2016-10-16 17:15
 */

namespace common\libs;

use backend\models\UserCertification;
use backend\models\UserConsumption;
use backend\models\UserItem;
use common\models\Comment;
use common\models\Complaints;
use common\models\Job;
use common\models\JobInfo;
use common\models\JobRecord;
use common\models\JobType;
use common\models\Mission;
use common\models\Order;
use common\models\User;
use Yii;
use yii\base\InvalidParamException;

class Constants
{

    const YesNo_Yes = 1;
    const YesNo_No = 0;

    public static function getYesNoItems($key = null)
    {
        $items = [
            self::YesNo_Yes => Yii::t('app', 'Yes'),
            self::YesNo_No  => Yii::t('app', 'No'),
        ];

        return self::getItems($items, $key);
    }

    public static function getWebsiteStatusItems($key = null)
    {
        $items = [
            self::YesNo_Yes => Yii::t('app', 'Opened'),
            self::YesNo_No  => Yii::t('app', 'Closed'),
        ];

        return self::getItems($items, $key);
    }

    const COMMENT_INITIAL = 0;
    const COMMENT_PUBLISH = 1;
    const COMMENT_RUBISSH = 2;

    public static function getCommentStatusItems($key = null)
    {
        $items = [
            self::COMMENT_INITIAL => Yii::t('app', 'Not Audited'),
            self::COMMENT_PUBLISH => Yii::t('app', 'Passed'),
            self::COMMENT_RUBISSH => Yii::t('app', 'Unpassed'),
        ];

        return self::getItems($items, $key);
    }

    const TARGET_BLANK = '_blank';
    const TARGET_SELF = '_self';

    public static function getTargetOpenMethod($key = null)
    {
        $items = [
            self::TARGET_BLANK => Yii::t('app', 'Yes'),
            self::TARGET_SELF  => Yii::t('app', 'No'),
        ];

        return self::getItems($items, $key);
    }


    const HTTP_METHOD_ALL = 0;
    const HTTP_METHOD_GET = 1;
    const HTTP_METHOD_POST = 2;

    public static function getHttpMethodItems($key = null)
    {
        $items = [
            self::HTTP_METHOD_ALL  => 'all',
            self::HTTP_METHOD_GET  => 'get',
            self::HTTP_METHOD_POST => 'post',
        ];

        return self::getItems($items, $key);
    }

    const PUBLISH_YES = 1;
    const PUBLISH_NO = 0;

    public static function getArticleStatus($key = null)
    {
        $items = [
            self::PUBLISH_YES => Yii::t('app', 'Publish'),
            self::PUBLISH_NO  => "隐藏",
        ];

        return self::getItems($items, $key);
    }

    const INPUT_INPUT = 1;
    const INPUT_TEXTAREA = 2;
    const INPUT_UEDITOR = 3;
    const INPUT_IMG = 4;

    public static function getInputTypeItems($key = null)
    {
        $items = [
            self::INPUT_INPUT    => 'input',
            self::INPUT_TEXTAREA => 'textarea',
            self::INPUT_UEDITOR  => 'ueditor',
            self::INPUT_IMG      => 'image',
        ];

        return self::getItems($items, $key);
    }

    const ARTICLE_VISIBILITY_PUBLIC = 1;
    const ARTICLE_VISIBILITY_COMMENT = 2;
    const ARTICLE_VISIBILITY_SECRET = 3;
    const ARTICLE_VISIBILITY_LOGIN = 4;

    public static function getArticleVisibility($key = null)
    {
        $items = [
            self::ARTICLE_VISIBILITY_PUBLIC  => Yii::t('app', 'Public'),
            self::ARTICLE_VISIBILITY_COMMENT => Yii::t('app', 'Reply'),
            self::ARTICLE_VISIBILITY_SECRET  => Yii::t('app', 'Password'),
            self::ARTICLE_VISIBILITY_LOGIN   => Yii::t('app', 'Login'),
        ];

        return self::getItems($items, $key);
    }

    const Status_Enable = 1;
    const Status_Desable = 0;

    public static function getStatusItems($key = null)
    {
        $items = [
            self::Status_Enable  => Yii::t('app', 'Enable'),
            self::Status_Desable => Yii::t('app', 'Disable'),
        ];

        return self::getItems($items, $key);
    }

    private static function getItems($items, $key = null)
    {
        if ($key !== null) {
            if (key_exists($key, $items)) {
                return $items[$key];
            }
            throw new InvalidParamException('Unknown key:' . $key);
        }

        return $items;
    }

    const AD_IMG = 1;
    const AD_VIDEO = 2;
    const AD_TEXT = 3;

    public static function getAdTypeItems($key = null)
    {
        $items = [
            self::AD_IMG   => 'image',
            self::AD_VIDEO => 'video',
            self::AD_TEXT  => 'text',
        ];

        return self::getItems($items, $key);
    }

    public static function getGenderNeeded($key = null)
    {
        $items = [
            JobInfo::GENDER_NEED_MAN   => '男',
            JobInfo::GENDER_NEED_WOMEN => '女',
            JobInfo::GENDER_NEED_ALL   => '不限'
        ];

        return self::getItems($items, $key);
    }

    public static function getPayStatus($key = null)
    {
        $items = [
            Job::PAY_STATUS     => '已支付',
            Job::NOT_PAY_STATUS => '未支付'
        ];

        return self::getItems($items, $key);
    }


    public static function getForbiddenStatus($key = null)
    {
        $items = [
            Job::FORBIDDEN => "屏蔽",
            10             => "正常",
        ];

        return self::getItems($items, $key);
    }


    public static function getPayNeeded($key = null)
    {
        $items = [
            Job::PAY_NEEDED     => "需要支付",
            Job::NOT_PAY_STATUS => "不需要支付",
        ];

        return self::getItems($items, $key);
    }

    public static function getSalaryType($key = null)
    {
        $items = [
            JobInfo::SALARY_TYPE_DAY   => '元/天',
            JobInfo::SALARY_TYPE_WEEK  => '元/周',
            JobInfo::SALARY_TYPE_MONTH => '元/月',
        ];

        return self::getItems($items, $key);
    }


    public static function getPayType($key = null)
    {
        $items = [
            JobInfo::PAY_TYPE_DAY   => '日结',
            JobInfo::PAY_TYPE_WEEK  => '周结',
            JobInfo::PAY_TYPE_MONTH => '月结',
        ];

        return self::getItems($items, $key);
    }

    public static function getPayTypeMission($key = null)
    {
        $items = [
            Mission::PAY_TYPE_TAIL     => '尾款',
            Mission::PAY_TYPE_FINESSES => '完工结',
        ];

        return self::getItems($items, $key);
    }


    public static function getCertificationType($key = null)
    {
        $items = [
            UserCertification::PERSONAL_TYPE => "个人认证",
            UserCertification::BUSINESS_TYPE => "商家认证",
        ];

        return self::getItems($items, $key);
    }

    public static function getCertificationStatus($key = null)
    {
        $items = [
            UserCertification::WAIT_STATUS    => "未审核",
            UserCertification::SUCCESS_STATUS => "审核通过",
            UserCertification::ERROR_STATUS   => "审核未通过",
        ];

        return self::getItems($items, $key);
    }

    public static function getComplaintsStatus($key = null)
    {
        $items = [
            Complaints::STATUS_WAIT => "未处理",
            Complaints::STATUS_DEAL => "已处理",
        ];

        return self::getItems($items, $key);
    }


    public static function getSearchPartTypes($key = null)
    {
        $items = [
            JobType::TYPE_LOCATION => "位置",
            JobType::TYPE_SALARY   => "工资",
//            JobType::TYPE_TIME     => "时间",
        ];

        return self::getItems($items, $key);
    }

    public static function getOrderStatus($key = null)
    {
        $items = [
            Order::STATUS_NOT_PAY     => "未支付",
            Order::STATUS_PAY_SUCCESS => "支付成功"
        ];

        return self::getItems($items, $key);
    }

    public static function getOrderType($key = null)
    {
        $items = [
            Order::TYPE_PART_TIME_POST           => "兼职发布",
            Order::TYPE_PART_TIME_VIP            => "兼职会员",
            Order::TYPE_MISSION_POST             => "江湖任务发布",
            Order::TYPE_MISSION_SMS              => "任务短信订阅",
            Order::TYPE_MISSION_SIGN_UP_CHARGE   => "查看任务报名",
            Order::TYPE_TAKE_MISSION             => "任务报名",
            Order::TYPE_PART_TIME_SIGN_UP_CHARGE => "查看兼职报名",
        ];

        return self::getItems($items, $key);
    }


    public static function getUserItemType($key = null)
    {
        $items = [
            UserItem::TYPE_ITEM => "权限",
            UserItem::TYPE_ROLE => "角色",
        ];

        return self::getItems($items, $key);
    }

    public static function getUserConsumptionType($key = null)
    {
        $items = [
            UserConsumption::TYPE_WX => "微信支付",
        ];

        return self::getItems($items, $key);
    }

    public static function getUserStatus($key = null)
    {
        $items = [
            User::STATUS_ACTIVE  => "正常",
            User::STATUS_DELETED => "禁用"
        ];

        return self::getItems($items, $key);
    }

    public static function getGender($key = null)
    {
        $items = [
            User::WOMAN => "女",
            User::MAN   => "男",
        ];

        return self::getItems($items, $key);
    }

    public static function getJobRecordStatus($key = null)
    {
        $items = [
            JobRecord::STATUS_CANCEL   => "取消报名",
            JobRecord::STATUS_SIGN_UP  => "报名",
            JobRecord::STATUS_FINESSES => "结束",
            JobRecord::STATUS_NOT_PAY  => "未付款",
        ];

        return self::getItems($items, $key);
    }
}
